-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Web Audio priming/blessing #3974
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compulim
requested review from
a-b-r-o-w-n,
beyackle,
cwhitten,
srinaath,
tdurnford and
tonyanziano
as code owners
July 6, 2021 18:26
This was referenced Jul 6, 2021
cwhitten
reviewed
Jul 6, 2021
cwhitten
approved these changes
Jul 6, 2021
This was referenced Jul 7, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changelog Entry
Added
AudioContext
when clicking on microphone button, by @compulim, in PR #3974Fixed
Description
Instead of using microphone input source from Speech SDK (a.k.a.
AudioConfig.fromMicrophone
), we are implementing our own audio input source. For a few reasons:AudioContext
need to be primed/blessedAudioContext.resume()
from code that is initiated from user gestures, such as clicking on the microphone buttonAudioContext
should be reused to keep its blessing statusHowever, the adapter provided by Speech SDK:
AudioContext
, always close after useAudioContext.resume()
from a user gesture eventThis means, in Safari, it may occasionally lose access to microphone.
We also added new internal hook
useResumeAudioContext
. So we can call the hook to from time to time to bless theAudioContext
continuously.Design
We are based from Speech SDK
AudioConfig.fromStreamInput
andPush/PullAudioInputStream
.There are few caveats with
Push/PullAudioInputStream
:PushAudioInputStream
write()
occasionally to push buffer to itPullAudioInputStream
PullAudioInputStream
will call continuously to pull buffer from usPullAudioInputStream
is set up, all data must be ready synchronouslyt=0
Instead of basing off
Push/PullAudioInputStream
, we are basing off from their base classAudioInputStream
instead. But there are lot of quirks in their original implementation.attach
is called, butdetach
is never calledturnOff
is called, butturnOn
is never calledclose
is marked as abstract (must implement), but never calledWe wrapped Speech SDK
AudioInputStream
implementation, cleaning up quirks, and internally expose ascreateAudioConfig
, which only requires 1 callback:attach
, which returns aPromise
of:ArrayBuffer
chunksturnOff
(optional), which will be called before the device is tearing downWe use our
createAudioConfig
in 2 different areas to proof its efficiency: real microphone input, and mocked input in test harness.In the future, when we bump Speech SDK, we will need to make sure our
createAudioConfig
will continue to work with their latest version.Specific Changes
createAudioConfig
for implementing customAudioConfig
for Speech SDK without understanding its complexityaudioConfig
is not passed, we will use our customAudioConfig
for microphone inputbotframework-directlinespeech-sdk
alone without Web Chat, it will NOT use our customAudioConfig
createAudioConfig
useResumeAudioContext
hook to continuously blessAudioContext
objectAudioContext
object whenpointerdown
event is received fromwindow
objectCHANGELOG.md
Review Checklist
Accessibility reviewed (tab order, content readability, alt text, color contrast)CSS styles reviewed (minimal rules, noz-index
)Documents reviewed (docs, samples, live demo)Internationalization reviewed (strings, unit formatting)package.json
andpackage-lock.json
reviewedSecurity reviewed (no data URIs, check for nonce leak)